home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / bbsutil / bsrc_250.zip / B_SPAWN.C < prev    next >
C/C++ Source or Header  |  1991-09-15  |  14KB  |  442 lines

  1. /*--------------------------------------------------------------------------*/
  2. /*                                                                          */
  3. /*                                                                          */
  4. /*      ------------         Bit-Bucket Software, Co.                       */
  5. /*      \ 10001101 /         Writers and Distributors of                    */
  6. /*       \ 011110 /          Freely Available<tm> Software.                 */
  7. /*        \ 1011 /                                                          */
  8. /*         ------                                                           */
  9. /*                                                                          */
  10. /*  (C) Copyright 1987-91, Bit Bucket Software Co., a Delaware Corporation. */
  11. /*                                                                          */
  12. /*                                                                          */
  13. /*            This module was originally written by Bob Hartman             */
  14. /*                                                                          */
  15. /*                                                                          */
  16. /*                        BinkleyTerm "Spawn" module                        */
  17. /*                                                                          */
  18. /*                                                                          */
  19. /*    For complete  details  of the licensing restrictions, please refer    */
  20. /*    to the License  agreement,  which  is published in its entirety in    */
  21. /*    the MAKEFILE and BT.C, and also contained in the file LICENSE.250.    */
  22. /*                                                                          */
  23. /*    USE  OF THIS FILE IS SUBJECT TO THE  RESTRICTIONS CONTAINED IN THE    */
  24. /*    BINKLEYTERM  LICENSING  AGREEMENT.  IF YOU DO NOT FIND THE TEXT OF    */
  25. /*    THIS  AGREEMENT IN ANY OF THE  AFOREMENTIONED FILES,  OR IF YOU DO    */
  26. /*    NOT HAVE THESE FILES,  YOU  SHOULD  IMMEDIATELY CONTACT BIT BUCKET    */
  27. /*    SOFTWARE CO.  AT ONE OF THE  ADDRESSES  LISTED BELOW.  IN NO EVENT    */
  28. /*    SHOULD YOU  PROCEED TO USE THIS FILE  WITHOUT HAVING  ACCEPTED THE    */
  29. /*    TERMS  OF  THE  BINKLEYTERM  LICENSING  AGREEMENT,  OR  SUCH OTHER    */
  30. /*    AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO.      */
  31. /*                                                                          */
  32. /*                                                                          */
  33. /* You can contact Bit Bucket Software Co. at any one of the following      */
  34. /* addresses:                                                               */
  35. /*                                                                          */
  36. /* Bit Bucket Software Co.        FidoNet  1:104/501, 1:343/491             */
  37. /* P.O. Box 460398                AlterNet 7:491/0                          */
  38. /* Aurora, CO 80046               BBS-Net  86:2030/1                        */
  39. /*                                Internet f491.n343.z1.fidonet.org         */
  40. /*                                                                          */
  41. /* Please feel free to contact us at any time to share your comments about  */
  42. /* our software and/or licensing policies.                                  */
  43. /*                                                                          */
  44. /*--------------------------------------------------------------------------*/
  45.  
  46. /* Include this file before any other includes or defines! */
  47.  
  48. #include "includes.h"
  49.  
  50. #ifndef OS_2
  51. /*
  52.  
  53.    We now use Thomas Wagner's EXEC module to do our swapping.
  54.    There's probably no good reason why we can't just hack our
  55.    code to work with his as distributed. We'll put that on the
  56.    wishlist. For now, we hacked his and you'll find the
  57.    appropriate excerpts below.
  58.  
  59.  
  60.  
  61.    EXEC.H: EXEC function with memory swap - Main function header file.
  62.  
  63.    Public domain software by
  64.  
  65.         Thomas Wagner
  66.         Ferrari electronic GmbH
  67.         Beusselstrasse 27
  68.         D-1000 Berlin 21
  69.         Germany
  70. */
  71.  
  72. extern int do_exec (char *xfn, char *pars, int spawn, unsigned needed,
  73.                     char **envp);
  74.  
  75. /*
  76.    The EXEC function.
  77.  
  78.       Parameters:
  79.  
  80.          xfn      is a string containing the name of the file
  81.                   to be executed.
  82.  
  83.          pars     The program parameters.
  84.  
  85.          spawn    If 0, the function will terminate after the 
  86.                   EXECed program returns, the function will not return.
  87.  
  88.                   NOTE: If the program file is not found, the function 
  89.                         will always return with the appropriate error 
  90.                         code, even if 'spawn' is 0.
  91.  
  92.                   If non-0, the function will return after executing the
  93.                   program. If necessary (see the "needed" parameter),
  94.                   memory will be swapped out before executing the program.
  95.                   For swapping, spawn must contain a combination of the 
  96.                   following flags:
  97.  
  98.                      USE_EMS  (0x01)  - allow EMS swap
  99.                      USE_XMS  (0x02)  - allow XMS swap
  100.                      USE_FILE (0x04)  - allow File swap
  101.  
  102.                   The order of trying the different swap methods can be
  103.                   controlled with one of the flags
  104.  
  105.                      EMS_FIRST (0x00) - EMS, XMS, File (default)
  106.                      XMS_FIRST (0x10) - XMS, EMS, File
  107.  
  108.                   If swapping is to File, the attribute of the swap file
  109.                   can be set to "hidden", so users are not irritated by
  110.                   strange files appearing out of nowhere with the flag
  111.  
  112.                      HIDE_FILE (0x40)    - create swap file as hidden
  113.  
  114.                   and the behaviour on Network drives can be changed with
  115.  
  116.                      NO_PREALLOC (0x100) - don't preallocate
  117.                      CHECK_NET (0x200)   - don't preallocate if file on net.
  118.  
  119.                   This checking for Network is mainly to compensate for
  120.                   a strange slowdown on Novell networks when preallocating
  121.                   a file. You can either set NO_PREALLOC to avoid allocation
  122.                   in any case, or let the prep_swap routine decide whether
  123.                   to do preallocation or not depending on the file being
  124.                   on a network drive (this will only work with DOS 3.1 or 
  125.                   later).
  126.  
  127.          needed   The memory needed for the program in paragraphs (16 Bytes).
  128.                   If not enough memory is free, the program will 
  129.                   be swapped out. 
  130.                   Use 0 to never swap, 0xffff to always swap. 
  131.                   If 'spawn' is 0, this parameter is irrelevant.
  132.  
  133.          envp     The environment to be passed to the spawned
  134.                   program. If this parameter is NULL, a copy
  135.                   of the parent's environment is used (i.e.
  136.                   'putenv' calls have no effect). If non-NULL,
  137.                   envp must point to an array of pointers to
  138.                   strings, terminated by a NULL pointer (the
  139.                   standard variable 'environ' may be used).
  140.  
  141.       Return value:
  142.  
  143.          0x0000..00FF: The EXECed Program's return code
  144.          0x0101:       Error preparing for swap: no space for swapping
  145.          0x0102:       Error preparing for swap: program too low in memory
  146.          0x0200:       Program file not found
  147.          0x03xx:       DOS-error-code xx calling EXEC
  148.          0x0400:       Error allocating environment buffer
  149.          0x0500:       Swapping requested, but prep_swap has not 
  150.                        been called or returned an error.
  151.          0x0501:       MCBs don't match expected setup
  152.          0x0502:       Error while swapping out
  153. */
  154.  
  155.  
  156. /* Return codes (only upper byte significant) */
  157.  
  158. #define RC_PREPERR   0x0100
  159. #define RC_NOFILE    0x0200
  160. #define RC_EXECERR   0x0300
  161. #define RC_ENVERR    0x0400
  162. #define RC_SWAPERR   0x0500
  163.  
  164. /* Swap method and option flags */
  165.  
  166. #define USE_EMS      0x01
  167. #